/**
 * 
 */
package com.edocbase.desktop.plugins.driver;

import org.eclipse.draw2d.ActionEvent;
import org.eclipse.draw2d.ActionListener;
import org.eclipse.draw2d.Clickable;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.LineBorder;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.swt.graphics.Image;

import com.edocbase.biz.diary.entities.WebAccount;
import com.edocbase.desktop.lightweight.ui.LookAndFeel;
import com.edocbase.desktop.lightweight.widgets.RibbonCheckbox;

/**
 * @author X61
 *
 */
public class WebAccountFigure extends Clickable {
	private WebAccount account = null;
	private Label iconLabel = null;
	private Figure content = null;
	private RibbonCheckbox checkBox;
	public WebAccountFigure(WebAccount account) {
		super();
		this.account = account;
		checkBox = new RibbonCheckbox(account.getFullAccount());
		//content = new Label(account.getFullAccount());
		content = new Figure();
		content.setLayoutManager(new ToolbarLayout(false));
		iconLabel = new Label();
		setToolTip(new Label(account.getFullAccount()));
		//content.setBackgroundColor(LookAndFeel.BorderColor);
		iconLabel.setIconAlignment(PositionConstants.TOP);
		//content.setTextPlacement(PositionConstants.SOUTH);
		content.add(iconLabel);
		content.add(checkBox);
		setContents(content);
		setPreferredSize(150, 75);
		setBorder(new LineBorder(LookAndFeel.BorderColor));
		addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent event) {
				checkBox.setSelected(!checkBox.isSelected());
			}
		});
	}
	public WebAccount getAccount() {
		return account;
	}
	public void setAccount(WebAccount account) {
		this.account = account;
	}
	public void setIcon(Image image) {
		if (image == null) return;
		iconLabel.setIcon(image);
	}
	public void setText(String s) {
		checkBox.setText(s);
	}
	
	public boolean isSelected(){
		return checkBox.isSelected();
	}
}
